﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq;

/// <summary>
///SZJBXXcs 的摘要说明
/// </summary>
public partial class SZJBXX
{
    public enum LevelEdu { 本科 = 1, 硕士, 博士, 博士后, 教授 }
    public enum IsOrNot { 否 = 0, 是 = 1 }
    public enum statusSMRZ { 未实名认证 = 0, 认证中, 认证通过, 认证不通过 }
    public enum statusSZ { 正常 = 1, 冻结 }
    public enum typeUser { 个人 = 0, 机构 }
    public enum sex { 男 = 1, 女 }
    public static SZJBXX GetByID(int id)
    {

        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            return context.SZJBXX.FirstOrDefault(row => row.ID == id);
        }
    }

    public static List<SZJBXX> GetAll()
    {
        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            return context.SZJBXX.ToList();
        }
    }

    public void Add()
    {
        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            context.SZJBXX.InsertOnSubmit(this);
            context.SubmitChanges();
        }
    }

    public void Update()
    {
        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            this.GetType().GetMethod("Detach").Invoke(this, null);
            var tbl = context.GetTable<SZJBXX>();
            tbl.Attach(this);
            context.Refresh(RefreshMode.KeepCurrentValues, this);
            context.SubmitChanges();
        }
    }

    public static void Delete(int id)
    {
        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            var objItem = context.SZJBXX.FirstOrDefault(row => row.ID == id);
            if (objItem == null)
                return;
            context.SZJBXX.DeleteOnSubmit(objItem);
            context.SubmitChanges();
        }
    }

    public static void BadDelete(int ID)
    {
        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            SZJBXX objSZJBXX = SZJBXX.GetByID(ID);
            if (objSZJBXX == null)
                return;
            objSZJBXX.Enable_Flag = 0;
            objSZJBXX.Update();
        }
    }

    public static List<SZJBXX> GetAllByCondition(int shengID, int shiID, int quID, string name, int userType, int eduLevel, int gkxm, int gkjl, int rzStatus, string telphone, int szStatus, int userID, string TimeFrom, string TimeTo)
    {
        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            var query = from t in context.SZJBXX
                        where t.Enable_Flag == 1
                        select t;
            if (shengID != 0)
            {
                query = query.Where(row => row.ProvinceID == shengID);
            }
            if (shiID != 0)
            {
                query = query.Where(row => row.CityID == shiID);
            }
            if (quID != 0)
            {
                query = query.Where(row => row.ReginID == quID);
            }

            if (!string.IsNullOrEmpty(name))
            {
                query = query.Where(row => (row.Xing + row.Ming).Contains(name));
            }

            if (userType != 999)
            {
                query = query.Where(row => row.AddUserID == userType);
            }

            if (eduLevel != 999)
            {
                query = query.Where(row => row.JYCD == eduLevel);
            }

            if (gkxm != 999)
            {
                query = query.Where(row => row.YSMC == gkxm);
            }

            if (gkjl != 999)
            {
                query = query.Where(row => row.YSJL == gkjl);
            }

            if (rzStatus != 999)
            {
                query = query.Where(row => row.SMRZStatus == rzStatus);
            }

            if (!string.IsNullOrEmpty(telphone))
            {
                query = query.Where(row => row.Telphone.Contains(telphone));
            }

            if (szStatus != 999)
            {
                query = query.Where(row => row.Status == szStatus);
            }

            if (userID != 0)
            {
                query = query.Where(row => row.AddUserID == userID);
            }

            if (!string.IsNullOrEmpty(TimeFrom))
            {
                query = query.Where(row => row.EndTime >= DongDong.Common.Misc.ConvertToDateTime(TimeFrom));
            }

            if (!string.IsNullOrEmpty(TimeTo))
            {
                query = query.Where(row => row.EndTime <= DongDong.Common.Misc.ConvertToDateTime(TimeTo));
            }
            return query.OrderByDescending(row => row.EndTime).ToList();
        }
    }
}